package com.hospital.dao;


import com.hospital.domain.Register;
import org.apache.ibatis.annotations.*;

import java.sql.Date;
import java.util.List;

@Mapper
public interface RegisterDao {


    @Insert("insert into registinfo values(null,#{remarks},now(),#{price},#{relateWay}" +
            ",#{dayOfWeek},#{type},#{date},#{amorPM},#{serialNum},#{userID},#{doctorID})")
    public int addRegister(Register register);
    @Select("select * from userinfo,doctorinfo,registinfo " +
            "where userinfo.userID = #{userID} " +
            "and userinfo.userID = registinfo.userID " +
            "and doctorinfo.doctorID = registinfo.doctorID " +
            "and registinfo.registID not in (SELECT caserecordinfo.registID FROM caserecordinfo)  and `date` > current_date()"
    )
    public List<Register> selectRegisterByUserID(int userID);
    @Delete("delete from registinfo where registID=#{id}")
    public int deleteRegisterById(int id);

    public List<Register> selectRegisterByDoctorID(@Param("doctorID") int doctorID, @Param("date") Date date, @Param("userName") String userName, @Param("amorPM") String amorPm);

    @Select("SELECT COUNT(*) FROM registinfo WHERE doctorID = #{doctorID} AND userID = #{userID}\n" +
            "AND `date` = #{date} AND AMorPM = #{amorPM} AND registID NOT IN(SELECT registID FROM caserecordinfo)")
    public int selectTimesOrder(Register register);

    @Update("update registinfo set remarks = #{remarks} where registID = #{registID}")
    public int addinfor(@Param("remarks") String remarks,@Param("registID") int registID);

}
